package com.csd.fragment;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.csd.activity.EnterpriseApplayActivity;
import com.csd.activity.R;
import com.csd.base.BaseFragment;

/**
 * 首页
 *
 */
public class IndexFragment extends BaseFragment {

	private TextView tv_map,tv_list;
	private FragmentManager fManager;
	private FragmentTransaction transaction;
	private int index = 0;
	private MapSelectFragment mapFragment = new MapSelectFragment();
	private Button bt_applay;
	
	private void initView() {
		// TODO Auto-generated method stub
		
		bt_applay = (Button) rootView.findViewById(R.id.bt_car);
		bt_applay.setOnClickListener(this);
		
		tv_map = (TextView) rootView.findViewById(R.id.map);
		tv_list = (TextView) rootView.findViewById(R.id.list);
		tv_map.setBackgroundColor(Color.parseColor("#D2223D"));
		tv_map.setTextColor(Color.parseColor("#ffffff"));
		tv_list.setBackgroundColor(Color.parseColor("#ffffff"));
		tv_list.setTextColor(Color.parseColor("#000000"));
		tv_map.setOnClickListener(this);
		tv_list.setOnClickListener(this);
		fManager = getChildFragmentManager();
		transaction = fManager.beginTransaction().replace(R.id.index_content, mapFragment);
		transaction.commit();

	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.map:
			if(index == 0){
				return;
			}
			index = 0;
			transaction = getFragmentManager().beginTransaction();
			transaction.replace(R.id.index_content,mapFragment);
			transaction.commit();
			tv_map.setBackgroundColor(Color.parseColor("#D2223D"));
			tv_map.setTextColor(Color.parseColor("#ffffff"));
			tv_list.setBackgroundColor(Color.parseColor("#ffffff"));
			tv_list.setTextColor(Color.parseColor("#000000"));
			break;
		case R.id.list:
			if(index == 1){
				return;
			}
			index = 1;
			ListSelectFragment listFragment = new ListSelectFragment();
			transaction = getFragmentManager().beginTransaction();
			transaction.replace(R.id.index_content, listFragment);
			transaction.commit();
			tv_list.setBackgroundColor(Color.parseColor("#D2223D"));
			tv_list.setTextColor(Color.parseColor("#ffffff"));
			tv_map.setBackgroundColor(Color.parseColor("#ffffff"));
			tv_map.setTextColor(Color.parseColor("#000000"));
			break;
		case R.id.bt_car:
			Intent intent = new Intent(getActivity(), EnterpriseApplayActivity.class);
			startActivity(intent);
			
			break;
		default:
			break;
		}
	}


	@Override
	protected View initView(LayoutInflater inflater) {
		rootView = inflater.inflate(R.layout.activity_selectcar, null);
		initView();
		return rootView;
	}


	@Override
	protected void findViewById() {
		// TODO Auto-generated method stub
		
	}


	@Override
	protected void setListener() {
		// TODO Auto-generated method stub
		
	}


	@Override
	protected void initData(Bundle savedInstanceState) {
		
		
	}
}
